package cn.ibizlab.odoo.core.odoo_maintenance.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Imaintenance_team;
import cn.ibizlab.odoo.core.odoo_maintenance.domain.Maintenance_team;
import cn.ibizlab.odoo.core.odoo_maintenance.filter.Maintenance_teamSearchContext;
import cn.ibizlab.odoo.core.odoo_maintenance.service.IMaintenance_teamService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[保养团队] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Maintenance_teamServiceImpl implements IMaintenance_teamService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Imaintenance_teamClientService maintenance_teamClientService;

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //maintenance_teamClientService.removeBatch(maintenance_teams) ;

    }

    @Override
    public void updateBatch(List<Maintenance_team> maintenance_teams, int batchSize) {

        //maintenance_teamClientService.updateBatch(maintenance_teams,batchSize) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Imaintenance_team clientModel = maintenance_teamClientService.createModel();
        clientModel.setId(id);
        maintenance_teamClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    @Override
    public boolean update(Maintenance_team maintenance_team) {
        boolean bOk = false ;
        Imaintenance_team clientModel = this.convert2Model(maintenance_team,null);
        maintenance_teamClientService.update(clientModel) ;
        this.convert2Domain(clientModel,maintenance_team) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Maintenance_team> maintenance_teams, int batchSize) {

                        //maintenance_teamClientService.createBatch(maintenance_teams,batchSize) ;

    }

    @Override
    public Maintenance_team get(Integer id) {
        Imaintenance_team clientModel = maintenance_teamClientService.createModel();
        clientModel.setId(id);
        maintenance_teamClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Maintenance_team get(Maintenance_team maintenance_team) {
        Maintenance_team retmaintenance_team = this.get(maintenance_team.getId()) ;
    	BeanCopier copier=BeanCopier.create(retmaintenance_team.getClass(), maintenance_team.getClass(), false);
        copier.copy(retmaintenance_team, maintenance_team, null);
        return maintenance_team ;
    }

    @Override
    public boolean create(Maintenance_team maintenance_team) {
        boolean bOk = false ;
        Imaintenance_team clientModel = this.convert2Model(maintenance_team,null);
        maintenance_teamClientService.create(clientModel) ;
        this.convert2Domain(clientModel,maintenance_team);
        bOk = true ;

        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Maintenance_team> searchDefault(Maintenance_teamSearchContext context) {
        List<Maintenance_team> list = new ArrayList<Maintenance_team>();
        Page<cn.ibizlab.odoo.core.client.model.Imaintenance_team> clientModelList = maintenance_teamClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imaintenance_team clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Maintenance_team>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据公司查询
     */
    @Override
    public Page<Maintenance_team> selectByOdoo_company(Integer id){
        Maintenance_teamSearchContext context = new Maintenance_teamSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Maintenance_team> list = new ArrayList<Maintenance_team>();
        Page<cn.ibizlab.odoo.core.client.model.Imaintenance_team> clientModelList = maintenance_teamClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imaintenance_team clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Maintenance_team>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Maintenance_team> selectByOdoo_create(Integer id){
        Maintenance_teamSearchContext context = new Maintenance_teamSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Maintenance_team> list = new ArrayList<Maintenance_team>();
        Page<cn.ibizlab.odoo.core.client.model.Imaintenance_team> clientModelList = maintenance_teamClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imaintenance_team clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Maintenance_team>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Maintenance_team> selectByOdoo_write(Integer id){
        Maintenance_teamSearchContext context = new Maintenance_teamSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Maintenance_team> list = new ArrayList<Maintenance_team>();
        Page<cn.ibizlab.odoo.core.client.model.Imaintenance_team> clientModelList = maintenance_teamClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Imaintenance_team clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Maintenance_team>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Imaintenance_team convert2Model(Maintenance_team domain , Imaintenance_team model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = maintenance_teamClientService.createModel() ;
        }

         if(domain.getTodo_request_count_blockDirtyFlag())
            model.setTodo_request_count_block(domain.getTodo_request_count_block());
         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getEquipment_idsDirtyFlag())
            model.setEquipment_ids(domain.getEquipment_ids());
         if(domain.getMember_idsDirtyFlag())
            model.setMember_ids(domain.getMember_ids());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getTodo_request_count_high_priorityDirtyFlag())
            model.setTodo_request_count_high_priority(domain.getTodo_request_count_high_priority());
         if(domain.getColorDirtyFlag())
            model.setColor(domain.getColor());
         if(domain.getNameDirtyFlag())
            model.setName(domain.getName());
         if(domain.getActiveDirtyFlag())
            model.setActive(domain.getActive());
         if(domain.getRequest_idsDirtyFlag())
            model.setRequest_ids(domain.getRequest_ids());
         if(domain.getTodo_request_countDirtyFlag())
            model.setTodo_request_count(domain.getTodo_request_count());
         if(domain.getTodo_request_idsDirtyFlag())
            model.setTodo_request_ids(domain.getTodo_request_ids());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getTodo_request_count_unscheduledDirtyFlag())
            model.setTodo_request_count_unscheduled(domain.getTodo_request_count_unscheduled());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getTodo_request_count_dateDirtyFlag())
            model.setTodo_request_count_date(domain.getTodo_request_count_date());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCompany_id_textDirtyFlag())
            model.setCompany_id_text(domain.getCompany_id_text());
         if(domain.getCompany_idDirtyFlag())
            model.setCompany_id(domain.getCompany_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
        return model ;
    }

    public Maintenance_team convert2Domain( Imaintenance_team model ,Maintenance_team domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Maintenance_team();
        }

        if(model.getTodo_request_count_blockDirtyFlag())
            domain.setTodo_request_count_block(model.getTodo_request_count_block());
        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getEquipment_idsDirtyFlag())
            domain.setEquipment_ids(model.getEquipment_ids());
        if(model.getMember_idsDirtyFlag())
            domain.setMember_ids(model.getMember_ids());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getTodo_request_count_high_priorityDirtyFlag())
            domain.setTodo_request_count_high_priority(model.getTodo_request_count_high_priority());
        if(model.getColorDirtyFlag())
            domain.setColor(model.getColor());
        if(model.getNameDirtyFlag())
            domain.setName(model.getName());
        if(model.getActiveDirtyFlag())
            domain.setActive(model.getActive());
        if(model.getRequest_idsDirtyFlag())
            domain.setRequest_ids(model.getRequest_ids());
        if(model.getTodo_request_countDirtyFlag())
            domain.setTodo_request_count(model.getTodo_request_count());
        if(model.getTodo_request_idsDirtyFlag())
            domain.setTodo_request_ids(model.getTodo_request_ids());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getTodo_request_count_unscheduledDirtyFlag())
            domain.setTodo_request_count_unscheduled(model.getTodo_request_count_unscheduled());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getTodo_request_count_dateDirtyFlag())
            domain.setTodo_request_count_date(model.getTodo_request_count_date());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCompany_id_textDirtyFlag())
            domain.setCompany_id_text(model.getCompany_id_text());
        if(model.getCompany_idDirtyFlag())
            domain.setCompany_id(model.getCompany_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        return domain ;
    }


}
